test: add IPNS/DNSLink with sub-path in value field#273
Conversation
existing IPNS tests only cover records whose Value is a bare /ipfs/<cid>. add TestGatewayIPNSRecordWithSubpath to verify gateways correctly handle IPNS records where Value contains a sub-path (e.g. /ipfs/<cid>/root2), testing both directory listing and file retrieval through path concatenation. reuses gateway-cache/fixtures.car and extends the shared IPNS record generator with makeSubpathRecord().
|
Results against Kubo master: Summary
|
|
Results against Kubo latest: Summary
|
add TestDNSLinkGatewayWithSubpath to verify gateways handle DNSLink TXT records where the path includes a sub-path (e.g. dnslink=/ipfs/<cid>/root2). also simplify TestGatewayIPNSRecordWithSubpath to only test file retrieval, removing the directory listing case.
v0.11.1Added
|
| RunWithSpecs(t, tests, specs.PathGatewayIPNS) | ||
| } | ||
|
|
||
| func TestGatewayIPNSRecordWithSubpath(t *testing.T) { |
There was a problem hiding this comment.
Explainer for posterity/llms (this is about IPNS, but similar applies to DNSLink one)
TestGatewayIPNSRecordWithSubpath
Verifies that a gateway correctly resolves IPNS records whose Value field
contains a sub-path (e.g. /ipfs/<cid>/sub/path) rather than a bare CID.
Shared fixture: gateway-cache/fixtures.car
A CARv1 file containing a UnixFS directory tree:
bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui (ROOT1_CID) ./
└── root2/
└── root3/
└── root4/
└── index.html -> "hello\n"
Key CIDs:
| Alias | CID | Path |
|---|---|---|
ROOT1_CID |
bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui |
./ |
ROOT2_CID |
bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii |
./root2 |
ROOT3_CID |
bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja |
./root2/root3 |
ROOT4_CID |
bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q |
./root2/root3/root4 |
FILE_CID |
bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am |
./root2/root3/root4/index.html |
IPNS record
Generated by makeSubpathRecord() in fixtures/ipns_records/generator/main.go.
It creates a valid V1+V2 IPNS record with a random Ed25519 key pair. The record's
Value field points at ROOT1_CID with a sub-path appended:
Value = /ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2
The resulting IPNS key (base36):
SUBPATH_IPNS_ID = k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c
The signed record is committed as a binary fixture at
fixtures/gateway-cache/k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c.ipns-record.
Test request
GET /ipns/k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c/root3/root4/index.html
Resolution steps
-
Gateway parses the request path:
- namespace:
/ipns/ - IPNS key:
k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c - remaining path:
/root3/root4/index.html
- namespace:
-
Gateway fetches and validates the IPNS record for that key.
-
Extracts the Value from the record:
/ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2 -
Concatenates the remaining request path onto the resolved Value:
/ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2 + /root3/root4/index.htmlFinal content path:
/ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2/root3/root4/index.html -
Resolves through the UnixFS DAG in
fixtures.car:
ROOT1_CID->root2/->root3/->root4/->index.html -
Expected response: 200 with body
hello\n
Why this matters
All prior IPNS tests used records whose Value was a bare /ipfs/<cid> with no
trailing path segments. This test covers the case where the IPNS record itself
embeds a sub-path in its Value. Gateways must concatenate the request path
after the full resolved Value, not just after the CID.
existing IPNS/DNSLink tests only cover records whose Value is a bare
/ipfs/<cid>.this PR adds basic tests to verify gateways correctly handle IPNS/TXT records where value contains a sub-path (e.g.
/ipfs/<cid>/root2).Changes:
TestGatewayIPNSRecordWithSubpathverifies gateways handle IPNS records where Value contains a sub-path (e.g./ipfs/<cid>/root2). Later simplified to only test file retrieval (directory listing case removed).TestDNSLinkGatewayWithSubpathverifies gateways handle DNSLink TXT records with sub-paths (e.g.dnslink=/ipfs/<cid>/root2).gateway-cache/fixtures.carand extends the shared IPNS record generator withmakeSubpathRecord().